<?php
class setting_admin extends controller{
	public function __construct(){		
		self::load_setting();
	}
	public function index(){
		$adminMenu= $this->load->module('adminMenu/index');
		
		$general=self::get_admin();
		$templateAdmin=array_filter(glob(FCPATH.'template/*'), 'is_dir');
		
		$data=array(
				'update_footer'=>'Starview ',
				'admin_title'=>'Setting Médias',
				'admin_menu'=>$adminMenu->generateAdminMenu(),
				'templateAdmin'=>$templateAdmin,
				'general'=>$general
		);
		
		
		$this->view(
				array('admin-header',
						'admin',
					'admin-footer'),
				$data); // Display the page
	}
	public function create(){
		$data = $this->input->post('general');
		$return=$this->model()->create($data);
	
		$this->load->helper('url');
		redirect('setting/admin');
	}
	public function get_admin(){
		$default=array(
				'base_url'=>'http://www.site.com','name'=>'',
				'description'=>'','admin_email'=>'admin@site.com',
				'date_format'=>'d-m-Y',
				'admin_template'=>"admin",
				'admin_currency'=>'€');
		$general=$this->model()->get_admin();
		if(empty($general))$general=$default;
		return $general;
	}

	public function load_setting($settingCode='admin'){
		$methode='get_'.$settingCode;
		$setting_config=$this->model()->$methode();
	
		if(!empty($setting_config))
			foreach ($setting_config as $keyConfig=>$valueConfig)
				CI::$APP->config->config[$keyConfig]=$valueConfig;
		if(isset($setting_config['admin_template']))$this->template=$setting_config['admin_template'];
		return $setting_config;
	}
	public function get_setting($name,$settingCode='admin'){
		$methode='get_'.$settingCode;
		$setting_config=$this->model()->$methode();		
		if(!empty($setting_config) and isset($setting_config[$name])) return $setting_config[$name];
		return false;
		
	}
}